<?php
/**
 * @file fashiontalkdefine.php
 * @author CaoQiCheng
 * @date 2016年5月26日 下午17:05:11
 * @brief 
 */
namespace haibao\cms\business\fashiontalk;

use \haibao\cms\data\fashiontalk\FashionTalkDefine as FashionTalkDefineData;
use \haibao\app\business\BusinessException;
use \haibao\cms\model\filter\fashiontalk\FashionTalkDefine as FashionTalkDefineFilter;
use \haibao\cms\model\filter\fashiontalk\FashionTalkImage as FashionTalkImageFilter;
use \haibao\cms\model\filter\fashiontalk\FashionTalkInterview as FashionTalkInterviewFilter;
use \haibao\cms\model\filter\User as UserFilter;
use haibao\frame\data\query\Condition;

class FashionTalkDefine extends \haibao\cms\business\Base{
	const TYPE_DESINGER = 1;
	const TYPE_CELEBRITY = 2;
	const TYPE_MODEL = 3;
	const TYPE_STYLIST = 4;
	const TYPE_BRAND = 5;
	const TYPE_STAR = 6;
	/**
	 * 访谈人物属性
	 */
	public static $InterviewType = array(
			self::TYPE_DESINGER => '设计师',
			self::TYPE_CELEBRITY => '明星',
			self::TYPE_MODEL => '模特',
			self::TYPE_STYLIST => '造型师',
			self::TYPE_BRAND => '品牌高层',
			self::TYPE_STAR => '时尚博主',
	);
	public static function getAll($query,$tag=true){
		$data = new FashionTalkDefineData();
		if($tag){
			return $data->getAll($query);
		}else {
			return $data->getOne($query);
		}
		
	}
	
	public static function getMonths(){
		$data = new FashionTalkDefineData();
	
		return $data->getMonths();
	}
	
	public static function updateClickNum($id){
		$data = new FashionTalkDefineData();
		$data->updateClickNum($id);
	}
	
	public static function saveFashiontalkInfo($model,$fashiontalkImageArr,$fashiontalkInterviewArr,$fashiontalkProperty=null){
		$funcCode = $model->Id ? self::FUNC_CODE_FASHIONTALK_EDIT : self::FUNC_CODE_FASHIONTALK_ADD;
		self::checkOperation($funcCode);
		
		if(!$model->InterviewType){
			throw new BusinessException('访谈人类型不能为空');
		}
		if(!$model->Title){
			throw new BusinessException('访谈标题不能为空');
		}
		if(!$model->Lead){
			throw new BusinessException('访谈导语不能为空');
		}
		if(!$model->Interviewee){
			throw new BusinessException('被访谈人不能为空');
		}
		if(!$model->PublishTime){
			throw new BusinessException('访谈发布时间不能为空');
		}
		if(!$model->AccessUrl){
			throw new BusinessException('URL关键字不能为空');
		}
		
		$fashiontalkDefineData = new FashionTalkDefineData();
		$fashiontalkDefineData->saveFashiontalkInfo($model, $fashiontalkImageArr, $fashiontalkInterviewArr,$fashiontalkProperty);
		self::saveOperateHistory($funcCode, $model->toArray(true,true));
		
	}
	/**
	 * 获取一条数据
	 */
	public static function getOneFashiontalkById($fashiontalkId){
		$fashiontalkDefineData = new FashionTalkDefineData();
		return $fashiontalkDefineData->getOneById($fashiontalkId);
	}
	/**
	 * 判断唯一链接
	 */
	public static function getAccessUrlIsExist($AccessUrl,$fashionTalkId=0){
		$fashiontalkDefineData = new FashionTalkDefineData();
		return $fashiontalkDefineData->getAccessUrlIsExist($AccessUrl,$fashionTalkId);
	}
	
	/**
	 * 根据id获取专访信息
	 */
	public static function getFashiontalkDefineInfo($fashiontalkId){
		if(!$fashiontalkId){
			return false;
		}
		$fashiontalkDefineFilter = new FashionTalkDefineFilter();
		$fashiontalkDefineFilter->select(array(
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_ID,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_ARTICLEID,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_EDITOR,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_CREATETIME,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_INTERVIEWEE,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_INTERVIEWTYPE,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_ISLINKARTICLE,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_LEAD,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_METADESCRIPTION,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_METATITLE,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_METAKEYWORDS,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_PICSOURCE,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_PUBLISHED,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_PUBLISHTIME,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_TITLE,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_VIDEOURL,
				$fashiontalkDefineFilter::CONDITION_FIELD_NAME_ACCESSURL,
		));
		$fashiontalkImageFilter = new FashionTalkImageFilter();
		$fashiontalkImageFilter->select(array(
				$fashiontalkImageFilter::CONDITION_FIELD_NAME_ID,
				$fashiontalkImageFilter::CONDITION_FIELD_NAME_SHOWTYPE,
				$fashiontalkImageFilter::CONDITION_FIELD_NAME_FASHIONTALKID,
				$fashiontalkImageFilter::CONDITION_FIELD_NAME_PICDESC,
				$fashiontalkImageFilter::CONDITION_FIELD_NAME_PICURL,
				$fashiontalkImageFilter::CONDITION_FIELD_NAME_SORTNUM
		));
		$fashiontalkInterviewFilter = new FashionTalkInterviewFilter();
		$fashiontalkInterviewFilter->select(array(
				$fashiontalkInterviewFilter::CONDITION_FIELD_NAME_ABBREVIATIONS,
				$fashiontalkInterviewFilter::CONDITION_FIELD_NAME_ABBREVIATIONSDESC,
				$fashiontalkInterviewFilter::CONDITION_FIELD_NAME_ANSWER,
				$fashiontalkInterviewFilter::CONDITION_FIELD_NAME_FASHIONTALKID,
				$fashiontalkInterviewFilter::CONDITION_FIELD_NAME_ID,
				$fashiontalkInterviewFilter::CONDITION_FIELD_NAME_QUESTION,
		));
		
		$fashiontalkDefineFilter->where(FashionTalkDefineFilter::CONDITION_FIELD_NAME_ID, Condition::CONDITION_EQUAL, $fashiontalkId);
		$fashiontalkDefineFilter->where(FashionTalkDefineFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, \haibao\cms\model\data\fashiontalk\FashionTalkDefine::STATUS_ON);
		
		$fashiontalkDefineFilter->leftJoin($fashiontalkImageFilter,null,FashionTalkDefineFilter::CONDITION_FIELD_NAME_ID,FashionTalkImageFilter::CONDITION_FIELD_NAME_FASHIONTALKID,FashionTalkDefineFilter::CONDITION_FIELD_NAME_IMAGE);
		$fashiontalkDefineFilter->leftJoin($fashiontalkInterviewFilter,null,FashionTalkDefineFilter::CONDITION_FIELD_NAME_ID,FashionTalkInterviewFilter::CONDITION_FIELD_NAME_FASHIONTALKID,FashionTalkDefineFilter::CONDITION_FIELD_NAME_INTERVIEW);
		
		$data = new FashionTalkDefineData();
		$result = $data->getOne($fashiontalkDefineFilter);
		return $result;
	}
	
	
	/**
	 * 删除尚道
	 */
	public static function delFashiontalkById($fashiontalkId){
		self::checkOperation(\haibao\cms\business\Base::FUNC_CODE_FASHIONTALK_DELETE);
		if(!$fashiontalkId){
			throw new BusinessException('专题Id不能为空');
		}
	
		$data  = new FashiontalkDefineData();
		$data->delFashiontalkById($fashiontalkId);
		self::saveOperateHistory(\haibao\cms\business\Base::FUNC_CODE_FASHIONTALK_DELETE, $fashiontalkId);
	}

	/**
	 * 添加model
	 */
	public static function addModel($model){
		$data  = new FashiontalkDefineData();
		$data->addAll($model);
	}
	
	/**
	 * 根据真名取得笔名
	 */
	public static function getUserPenName($realNameArr){
		$realNameArr = explode(',', $realNameArr);
		$userList = array();
		$userFilter = new UserFilter();
		$userFilter->select(array(
				$userFilter::CONDITION_FIELD_NAME_ID,
				$userFilter::CONDITION_FIELD_NAME_PEN_NAME,
				$userFilter::CONDITION_FIELD_NAME_REAL_NAME,
		));
		$userFilter->where(UserFilter::CONDITION_FIELD_NAME_REAL_NAME, Condition::CONDITION_IN,$realNameArr);
		$result = self::getAll($userFilter);
		return $result;
	}
	
	
	
}